package main

import (
	"fmt"
	"sync"
)

var a int32
var b = make(chan int, 1)

func main() {
	var wg sync.WaitGroup

	wg.Add(2)

	go func(wg *sync.WaitGroup) {
		var i int32

		for ; i < 10000; i++ {
			<-b
			a += 1
			b <- 1
		}
		defer wg.Done()

	}(&wg)
	go func(wg *sync.WaitGroup) {
		var i int32
		for ; i < 100000; i++ {
			<-b
			a += 1
			b <- 1
		}
		defer wg.Done()

	}(&wg)
	b <- 1
	wg.Wait()
	<-b
	fmt.Println(a)
}
